package com.android.websms;

import android.content.ContentUris;
import android.content.Context;
import android.graphics.Bitmap;
import android.provider.MediaStore;

import com.android.webserver.fwapi.RawRessource;
import com.android.webserver.fwapi.Request;

public class Picture extends RawRessource
{

	public Picture(Context context, Request request)
	{
		super(context, request);
	}

	@Override
	protected boolean create(Object... objects)
	{
		String id = getGETParameter("id");
		if (id == null)
			return false;

		Bitmap bitmap = null;

		if (getGETParameter("thumbnail") != null)
		{
			bitmap = MediaStore.Images.Thumbnails.getThumbnail(
					context.getContentResolver(), Integer.parseInt(id),
					MediaStore.Images.Thumbnails.MICRO_KIND, null);
		}
		else
			try
			{
				bitmap = MediaStore.Images.Media.getBitmap(context.getContentResolver(),
						ContentUris.withAppendedId(
								MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
								Integer.parseInt(id)));
			}
			catch (Exception e)
			{
				e.printStackTrace();
				return false;
			}

		return getImage(bitmap);
	}
}
